home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / include / tradstdc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  7.4 KB  |  255 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)tradstdc.h    3.1    93/05/30    */
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #ifndef TRADSTDC_H
  6. #define TRADSTDC_H
  7.  
  8. #if defined(DUMB) && !defined(NOVOID)
  9. #define NOVOID
  10. #endif
  11.  
  12. #ifdef NOVOID
  13. #define void int
  14. #endif
  15.  
  16. #if defined(__STDC__) && !defined(NOTSTDC)
  17. #define NHSTDC
  18. #endif
  19.  
  20. #if defined(ultrix) && defined(__STDC__) && !defined(__LANGUAGE_C)
  21. /* Ultrix seems to be in a constant state of flux.  This check attempts to
  22.  * set up ansi compatibility if it wasn't set up correctly by the compiler.
  23.  */
  24. #ifdef mips
  25. #define __mips mips
  26. #endif
  27.  
  28. #ifdef LANGUAGE_C
  29. #define __LANGUAGE_C LANGUAGE_C
  30. #endif
  31.  
  32. #endif
  33.  
  34. /*
  35.  * ANSI X3J11 detection.
  36.  * Makes substitutes for compatibility with the old C standard.
  37.  */
  38.  
  39. /* Decide how to handle variable parameter lists:
  40.  * USE_STDARG means use the ANSI <stdarg.h> facilities (only ANSI compilers
  41.  * should do this, and only if the library supports it).
  42.  * USE_VARARGS means use the <varargs.h> facilities.  Again, this should only
  43.  * be done if the library supports it.  ANSI is *not* required for this.
  44.  * Otherwise, the kludgy old methods are used.
  45.  * The defaults are USE_STDARG for ANSI compilers, and USE_OLDARGS for
  46.  * others.
  47.  */
  48.  
  49. /* #define USE_VARARGS        /* use <varargs.h> instead of <stdarg.h> */
  50. /* #define USE_OLDARGS        /* don't use any variable argument facilites */
  51.  
  52. #if defined(apollo)             /* Apollos have stdarg(3) but not stdarg.h */
  53. # define USE_VARARGS
  54. #endif
  55.  
  56. #if defined(NHSTDC) || defined(ULTRIX_PROTO) || defined(MAC)
  57. # if !defined(USE_VARARGS) && !defined(USE_OLDARGS) && !defined(USE_STDARG)
  58. #   define USE_STDARG
  59. # endif
  60. #endif
  61.  
  62. #ifdef NEED_VARARGS        /* only define these if necessary */
  63. #ifdef USE_STDARG
  64. # include <stdarg.h>
  65. # define VA_DECL(typ1,var1)    (typ1 var1, ...) { va_list the_args;
  66. # define VA_DECL2(typ1,var1,typ2,var2)    \
  67.     (typ1 var1, typ2 var2, ...) { va_list the_args;
  68. # define VA_INIT(var1,typ1)
  69. # define VA_NEXT(var1,typ1)    var1 = va_arg(the_args, typ1)
  70. # define VA_ARGS        the_args
  71. # define VA_START(x)        va_start(the_args, x)
  72. # define VA_END()        va_end(the_args)
  73. # if defined(ULTRIX_PROTO) && !defined(_VA_LIST_)
  74. #  define _VA_LIST_    /* prevents multiple def in stdio.h */
  75. # endif
  76. #else
  77. # ifdef USE_VARARGS
  78. #  include <varargs.h>
  79. #  define VA_DECL(typ1,var1)    (va_alist) va_dcl {\
  80.         va_list the_args; typ1 var1;
  81. #  define VA_DECL2(typ1,var1,typ2,var2)    (va_alist) va_dcl {\
  82.         va_list the_args; typ1 var1; typ2 var2;
  83. #  define VA_ARGS        the_args
  84. #  define VA_START(x)        va_start(the_args)
  85. #  define VA_INIT(var1,typ1)    var1 = va_arg(the_args, typ1)
  86. #  define VA_NEXT(var1,typ1)    var1 = va_arg(the_args,typ1)
  87. #  define VA_END()        va_end(the_args)
  88. # else
  89. #   define VA_ARGS    arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9
  90. #   define VA_DECL(typ1,var1)  (var1,VA_ARGS) typ1 var1; \
  91.     char *arg1,*arg2,*arg3,*arg4,*arg5,*arg6,*arg7,*arg8,*arg9; {
  92. #   define VA_DECL2(typ1,var1,typ2,var2)  (var1,var2,VA_ARGS) \
  93.     typ1 var1; typ2 var2;\
  94.     char *arg1,*arg2,*arg3,*arg4,*arg5,*arg6,*arg7,*arg8,*arg9; {
  95. #   define VA_START(x)
  96. #   define VA_INIT(var1,typ1)
  97. #   define VA_END()
  98. # endif
  99. #endif
  100. #endif /* NEED_VARARGS */
  101.  
  102. #if defined(NHSTDC) || defined(MSDOS) || defined(MAC) || defined(ULTRIX_PROTO)
  103.  
  104. /*
  105.  * Used for robust ANSI parameter forward declarations:
  106.  * int VDECL(sprintf, (char *, const char *, ...));
  107.  *
  108.  * NDECL() is used for functions with zero arguments;
  109.  * FDECL() is used for functions with a fixed number of arguments;
  110.  * VDECL() is used for functions with a variable number of arguments.
  111.  * Separate macros are needed because ANSI will mix old-style declarations
  112.  * with prototypes, except in the case of varargs, and the OVERLAY-specific
  113.  * trampoli.* mechanism conflicts with the ANSI <<f(void)>> syntax.
  114.  */
  115.  
  116. # define NDECL(f)    f(void)    /* Must be overridden if OVERLAY set later */
  117.  
  118. # define FDECL(f,p)    f p
  119.  
  120. # if defined(MSDOS) || defined(USE_STDARG)
  121. #  define VDECL(f,p)    f p
  122. # else
  123. #  define VDECL(f,p)    f()
  124. # endif
  125.  
  126. /* generic pointer, always a macro; genericptr_t is usually a typedef */
  127. # define genericptr    void *
  128.  
  129. # if defined(__TURBOC__) || (defined(ULTRIX_PROTO) && !defined(__GNUC__)) || defined(OS2_CSET2)
  130. /* Cover for stupid Turbo C */
  131. /* And Ultrix on a DECstation with 2.0 compiler, which coredumps on
  132.  *   typedef void * genericptr_t;
  133.  *   extern void a(void(*)(int, genericptr_t));
  134.  * Using the #define is OK for other compiler versions too.
  135.  */
  136. /* And IBM CSet/2.  The redeclaration of free hoses the compile. */
  137. #  define genericptr_t    genericptr
  138. # else
  139. #  if !defined(NHSTDC) && !defined(MAC)
  140. #   define const
  141. #   define signed
  142. #   define volatile
  143. #  endif
  144. # endif
  145.  
  146. /*
  147.  * Suppress `const' if necessary and not handled elsewhere.
  148.  * Don't use `#if defined(xxx) && !defined(const)'
  149.  * because some compilers choke on `defined(const)'.
  150.  * This has been observed with Lattice, MPW, and High C.
  151.  */
  152. # if (defined(ULTRIX_PROTO) && !defined(NHSTDC)) || defined(apollo)
  153.     /* the system header files don't use `const' properly */
  154. #  ifndef const
  155. #   define const
  156. #  endif
  157. # endif
  158.  
  159. #else /* NHSTDC */    /* a "traditional" C  compiler */
  160.  
  161. # define NDECL(f)    f()
  162. # define FDECL(f,p)    f()
  163. # define VDECL(f,p)    f()
  164.  
  165. # if defined(AMIGA) || defined(HPUX) || defined(POSIX_TYPES) || defined(__DECC)
  166. #  define genericptr    void *
  167. # endif
  168. # ifndef genericptr
  169. #  define genericptr    char *
  170. # endif
  171.  
  172. /*
  173.  * Traditional C compilers don't have "signed", "const", or "volatile".
  174.  */
  175. # define signed
  176. # define const
  177. # define volatile
  178.  
  179. #endif /* NHSTDC */
  180.  
  181.  
  182. #ifndef genericptr_t
  183. typedef genericptr genericptr_t;    /* (void *) or (char *) */
  184. #endif
  185.  
  186.  
  187. /*
  188.  * According to ANSI, prototypes for old-style declarations must widen the
  189.  * arguments to int.  However, the MSDOS compilers accept shorter arguments
  190.  * (char, short, etc.) in prototypes and do typechecking with them.  Therefore
  191.  * this mess to allow the better typechecking while also allowing some
  192.  * prototypes for the ANSI compilers so people quit trying to fix the
  193.  * prototypes to match the standard and thus lose the typechecking.
  194.  */
  195. #if defined(MSDOS) && !defined(__TURBOC__) && !defined(__GO32__)
  196. #define UNWIDENED_PROTOTYPES
  197. #endif
  198. #if defined(AMIGA) && !defined(AZTEC_50)
  199. #define UNWIDENED_PROTOTYPES
  200. #endif
  201. #if defined(MAC) && !defined(THINK_C)
  202. #define UNWIDENED_PROTOTYPES
  203. #endif
  204.  
  205. #if defined(ULTRIX_PROTO) && defined(ULTRIX_CC20)
  206. #define UNWIDENED_PROTOTYPES
  207. #endif
  208. #if defined(apollo)
  209. #define UNWIDENED_PROTOTYPES
  210. #endif
  211.  
  212. #ifndef UNWIDENED_PROTOTYPES
  213. # if defined(NHSTDC) || defined(__TURBOC__) || defined(ULTRIX_PROTO) || defined(THINK_C)
  214. # define WIDENED_PROTOTYPES
  215. # endif
  216. #endif
  217.  
  218. #if defined(sgi) && !defined(__GNUC__)
  219. /*
  220.  * As of IRIX 4.0.1, /bin/cc claims to be an ANSI compiler, but it thinks
  221.  * it's impossible for a prototype to match an old-style definition with
  222.  * unwidened argument types.  Thus, we have to turn off all NetHack
  223.  * prototypes, and avoid declaring several system functions, since the system
  224.  * include files have prototypes and the compiler also complains that
  225.  * prototyped and unprototyped declarations don't match.
  226.  */
  227. # undef NDECL
  228. # undef FDECL
  229. # undef VDECL
  230. # define NDECL(f)    f()
  231. # define FDECL(f,p)    f()
  232. # define VDECL(f,p)    f()
  233. #endif
  234.  
  235.  
  236. #ifdef __HC__    /* MetaWare High-C defaults to unsigned chars */
  237. # undef signed
  238. #endif
  239.  
  240.  
  241. /*
  242.  * Allow gcc2 to check parameters of printf-like calls with -Wformat;
  243.  * append this to a prototype declaration (see pline() in extern.h).
  244.  */
  245. #ifdef __GNUC__
  246. # if __GNUC__ >= 2
  247. #define PRINTF_F(f,v) __attribute__ ((format (printf, f, v)))
  248. # endif
  249. #endif
  250. #ifndef PRINTF_F
  251. #define PRINTF_F(f,v)
  252. #endif
  253.  
  254. #endif /* TRADSTDC_H */
  255.